﻿// Write a method ReadNumber(int start, int end) that enters an integer number in given range [start…end]. 
// If an invalid number or non-number text is entered, the method should throw an exception. 
// Using this method write a program that enters 10 numbers: a1, a2, … a10, such that 1 < a1 < … < a10 < 100

using System;

public class Read10IntegerNumbers
{
    public static int ReadNumber(int start, int end)
    {
        int number;
        if (!int.TryParse(Console.ReadLine(), out number))
        {
            throw new FormatException("Invalid number format");
        }

        if (number < start || end < number)
        {
            string message = string.Format("The number {0} must be greater than {1} and lower than {2}", number, start, end);
            throw new ArgumentOutOfRangeException(message);
        }

        return number;
    }

    public static void PrintArray(int[] numbers)
    {
        for (int i = 0; i < numbers.Length; i++)
        {
            Console.Write(numbers[i]);
            if (i < numbers.Length - 1)
            {
                Console.Write(" < ");
            }
        }
    }

    private static void Main()
    {
        int count = 10;
        int start = 1;
        int end = 100;
        int[] numbers = new int[10];

        for (int i = 0; i < count; i++)
        {
            Console.Write("Enter number ({0} < a{1} < {2}): ", start, i + 1, end);
            bool exit = true;
            while (exit)
            {
                try
                {
                    if (i > 0)
                    {
                        start = numbers[i - 1];
                    }
                    numbers[i] = ReadNumber(start, end);
                    exit = false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.Write("Enter number ({0} < a{1} < {2}): ", start, i + 1, end);
                }
            }
        }

        PrintArray(numbers);
        Console.WriteLine();
    }
}